package com.yanqu.road.server.logic.activity.condition.foxcard;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.foxcard.UserFoxCardData;
import com.yanqu.road.entity.activity.foxcard.config.FoxCardEffectCardConfig;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.logic.activity.foxcard.FoxCardConfig;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.foxcard.FoxCardModule;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseActivityCondition;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.foxcard.FoxCardMgr;

import java.math.BigInteger;

public class FoxCardOneCardUnlockCondition extends BaseActivityCondition {
    public FoxCardOneCardUnlockCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
        super(activityInfo, activityConditionInfo, baseActivityData);
    }

    @Override
    protected void player_BoardLevelHandle(Object object) {
//        if (isCompleted(player)) {
//            return;
//        }
        UserFoxCardData userData = player.getModule(FoxCardModule.class).getUserData();
        if (userData == null) {
            return;
        }
        int cardId = activityConditionInfo.getParamList().get(0).intValue();

        if (userData.getUnlockCards().contains(cardId)) {
            setValue(BigInteger.ONE);
        }
    }

    @Override
    public boolean isCompleted(GamePlayer player) {
        return getValue().compareTo(activityConditionInfo.getParamList().get(3)) >= 0;
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.FoxCardOneCardUnlock.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.FoxCardOneCardUnlock.getValue(), handle);
    }

    @Override
    public boolean canChange(ActivityInfo activityInfo) {
        if (ActivityMgr.activityInShowTime(activityInfo)) {
            return true;
        }
        return false;
    }
}
